import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../common/models/books.dart';
import '../index.dart';

class SqliteWidget extends GetView<SqliteController> {
  SqliteWidget({Key? key}) : super(key: key);

  final logic = Get.find<SqliteController>();
  final state = Get.find<SqliteController>().state;

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        children: [
          const SizedBox(height: 50),
          ElevatedButton(
            onPressed: () async {
              await logic.insertBooks();
              await logic.getAllBooks();
            },
            child: const Text('增加(增)'),
          ),
          const SizedBox(height: 20),
          ElevatedButton(
            onPressed: () async {
              await logic.getBooksInfo(2);
            },
            child: const Text('获取ID=2的数据'),
          ),
          const SizedBox(height: 20),
          ElevatedButton(
            onPressed: () async {
              await logic.getAllBooks();
              await logic.getBooksInfo(1);
            },
            child: const Text('打印所有数据'),
          ),
          const SizedBox(height: 20),
          ElevatedButton(
            onPressed: () async {
              await logic.deleteBookdById(1);
              await logic.getAllBooks();
            },
            child: const Text('删除指定id=1的数据'),
          ),
          const SizedBox(height: 20),
          ElevatedButton(
            onPressed: () async {
              Books books = Books(
                  bookId: 2,
                  bookName: 'The Great Gatsby1',
                  bookDesc: 'F. Scott Fitzgerald1',
                  createTime: DateTime.parse('2024-02-01'),
                  isChecked: false,
                  bookNum: 21);
              await logic.updateBooks(books);
              await logic.getAllBooks();
            },
            child: const Text('修改指定id=2的数据'),
          ),
        ],
      ),
    );
  }
}
